<template>
    <div class="cmt-container">
        <h3>发表评论</h3>
        <hr>
        <textarea placeholder="请输入要评论的内容（最多120字）" maxlength="120"></textarea>
        <mt-button type="primary" size="large">发表评论</mt-button>

        <div class="cmt-list" v-for="(item,i) in comments" :key="item.add_time">
            <div class="cmt-item">
                <div class="cmt-title">
                    第{{i+1}}楼&nbsp;&nbsp;用户:{{item.user_name}}&nbsp;&nbsp;发表时间:{{item.add_time | dateFormat}}
                </div>
                <div class="cmt-body">
                        {{item.content === 'undefined' ? '此用户很懒，啥都没说': item.content}}
                </div>
            </div>
        </div>



        <mt-button type="danger" size="large" plain @click="getMore">加载更多</mt-button>
    </div>
</template>

<script>
    export default {
        data(){
            return{
                /*pageIndex: 1, //默认展示第一页
                comments:[] //所有的评论数据*/
                comments:[
                    {user_name:"小1",add_time:new Date(),content:"11111"},
                    {user_name:"小2",add_time:new Date(),content:"22222"},
                    {user_name:"小3",add_time:new Date(),content:"33333"},
                    {user_name:"小4",add_time:new Date(),content:"undefined"},
                    {user_name:"小5",add_time:new Date(),content:"55555"},
                    {user_name:"小6",add_time:new Date(),content:"66666"},
                    {user_name:"小7",add_time:new Date(),content:"77777"},
                    {user_name:"小8",add_time:new Date(),content:"88888"},
                    {user_name:"小9",add_time:new Date(),content:"99999"},
                    {user_name:"小10",add_time:new Date(),content:"101010"},
                ],
                comments2:[
                    {user_name:"小王1",add_time:new Date(),content:"11111"},
                    {user_name:"小王2",add_time:new Date(),content:"22222"},
                    {user_name:"小王3",add_time:new Date(),content:"33333"},
                    {user_name:"小王4",add_time:new Date(),content:"undefined"},
                    {user_name:"小王5",add_time:new Date(),content:"55555"},
                    {user_name:"小王6",add_time:new Date(),content:"66666"},
                    {user_name:"小王7",add_time:new Date(),content:"77777"},
                    {user_name:"小王8",add_time:new Date(),content:"88888"},
                    {user_name:"小王9",add_time:new Date(),content:"99999"},
                    {user_name:"小王10",add_time:new Date(),content:"101010"},
                ]
             }
        },
       /* props:["id"],
        created(){
            this.getComments();
        },
        methods:{
            getMore(){
                this.pageIndex++;
                this.getComments();
            },
            getComments(){
                this.$http.get("api/getcomments/" + this.id + "?pageindex=" + this.pageIndex).then(result=>{
                    if(result.body.status === 0){
                        //this.comments = result.body.message;
                        //每当获取新数据的时候不要把老数据清空，而是应该以老数据【拼接】上新数据
                        this.comments = this.comments.concat(result.body.message);
                    }else{
                        Toast("失败")
                    }
                })
            }
        }*/
       methods:{
           getMore(){
               this.comments = this.comments.concat(this.comments2)
           }
       }
    }
</script>

<style scoped lang="scss">
        h3{
            font-size: 18px;
        }
        textarea{
            font-size: 14px;
            height: 85px;
            margin:0;
        }
        .cmt-list{
            margin: 10px 0;
        }
        .mt-item{
              font-size: 13px;
          }
        .cmt-title{
             line-height:30px;
             background-color: #ccc;
         }
        .cmt-body{
            line-height:35px;
            text-indent: 2em;
        }
</style>